package JUC;

import java.util.concurrent.TimeUnit;

//守护线程
public class Daemondemo {
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"\t 开始运行"+(Thread.currentThread().isDaemon() ? "守护线程":"用户线程"));
        },"t1");
        t1.start();
//        t1.setDaemon(true);必须在主线程开启之前 不然会报不合法异常

        //用户暂停几秒线程
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(Thread.currentThread().getName()+"\t ------end  主线程");
    }
}
